package com.wjk.kylin.mall.admin.controller;


import cn.hutool.core.map.MapUtil;
import com.wjk.kylin.mall.admin.dto.RouterDTO;
import com.wjk.kylin.mall.admin.entity.UserEntity;
import com.wjk.kylin.mall.admin.service.IMenuService;
import com.wjk.kylin.mall.admin.service.IRoleService;
import com.wjk.kylin.mall.admin.service.IUserService;
import com.wjk.kylin.mall.common.core.dto.base.BaseOutDTO;
import com.wjk.kylin.mall.common.core.dto.base.DataOutDTO;
import com.wjk.kylin.mall.common.redis.utils.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.*;
import java.util.List;


/**
 * @author wangjkui
 * @description 通用控制器
 * @date 2020/5/22
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/system")
public class SystemController {
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private IUserService userService;
    @Autowired
    private IRoleService roleService;
    @Autowired
    private IMenuService menuService;

    /**
     * 获取用户信息
     */
    @GetMapping("/getUserInfo")
    public BaseOutDTO getUserInfo() {
        //用户信息 TODO 1
        UserEntity user = userService.getById(1L);
        user.setPassword(null);//脱敏
        // 角色集合
        List<String> roleList = roleService.findRolePermissionByUser(user);
        // 权限集合
        List<String> permissionList = menuService.findMenuPermsByUserToUser(user);
        Map<String, Object> map = MapUtil.newHashMap(3);
        map.put("user", user);
        map.put("roleList", roleList);
        map.put("permissionList", permissionList);

        return DataOutDTO.builder().data(map).build();
    }

    /**
     * 获取路由信息
     */
    @GetMapping("/getRouters")
    public BaseOutDTO getRouters() {
        List<RouterDTO> list = menuService.getRouters(1L);

        return DataOutDTO.builder().data(list).build();
    }
}
